<script setup>
import { ref, onMounted, onBeforeUnmount, reactive } from 'vue'

// 左侧显示大屏名称及logo
const site = {
  logo: "./src/assets/img/logo.png",
  name: '中建10086局',
  SystemName: '汉口平汉铁路局旧址云数据中心'
}

// 右侧时间显示
const getCurrentTime = () => {
  const now = new Date();
  const date = `${now.getFullYear()}-${('0' + (now.getMonth() + 1)).slice(-2)}-${('0' + now.getDate()).slice(-2)}`;
  const weekDays = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  const week = weekDays[now.getDay()];
  const time = `${('0' + now.getHours()).slice(-2)}:${('0' + now.getMinutes()).slice(-2)}:${('0' + now.getSeconds()).slice(-2)}`;
  return `${date} ${week} ${time}`;
}
const currentTime = ref('');

const updateCurrentTime = () => {
  currentTime.value = getCurrentTime();
};

onMounted(() => {
  updateCurrentTime();
  const intervalId = setInterval(updateCurrentTime, 1000);
  onBeforeUnmount(() => {
    clearInterval(intervalId);
  });
})

const navIndex = ref('')
navIndex.value = sessionStorage.getItem('navIndex')
  ? sessionStorage.getItem('navIndex')
  : 0
const menuName = ref('首页')
const menuClass = ref('glyphicon glyphicon-menu-down')
const navList = [
  {
    name: '建筑模型',
    path: '/',
    children: []
  },
  {
    name: '建筑采风',
    path: '/picture',
    children: []
  },
  {
    name: '建筑信息',
    path: '/buildinginfo',
    children: []
  },
  {
    name: '构件信息',
    path: '/constructinfo',
    children: []
  },
  {
    name: '历史沿革',
    path: '/history',
    children: []
  },
  {
    name: '建筑特色',
    path: '/buildingFeature',
    children: []
  },
  {
    name: '综合价值',
    path: '/value',
    children: []
  },

  {
    name: '联系我们',
    path: '/contactus',
    children: []
  }
]
function navClick(index, name) {
  navIndex.value = index
  sessionStorage.setItem('navIndex', index)
  menuName.value = name
}
function menuClick() {
  if (menuClass.value == 'glyphicon glyphicon-menu-down') {
    menuClass.value = 'glyphicon glyphicon-menu-up'
  } else {
    menuClass.value = 'glyphicon glyphicon-menu-down'
  }
}
const isScrolled = ref(false);

const handleScroll = () => {
  if (window.scrollY > 0 && !isScrolled.value) {
    isScrolled.value = true;
  } else if (window.scrollY === 0 && isScrolled.value) {
    isScrolled.value = false;
  }
};

onMounted(() => {
  window.addEventListener('scroll', handleScroll);
});

onBeforeUnmount(() => {
  window.removeEventListener('scroll', handleScroll);
});
</script>


<template>
  <!-- 头部整体盒子 -->
  <div id="header" class="container-fuild">

    <!-- 头部顶部 -->
    <div class="header-top container-fuild hidden-xs">
      <div class="container">
          <img src="@/assets/header/logo.png" style="weight:auto;height: 50px" />
        <span class="name">{{ site.name }}</span>
        <div class="SystemName-container">
          <span class="SystemName" style="font-size:40px;font-style: italic;">{{ site.SystemName }}</span>
        </div>
        <span v-if="currentTime" class="currentTime">{{ currentTime }}</span>
      </div>
    </div>


    <div class="header-nav container hidden-xs"  >
      <!-- 导航内容 -->
      <ul class="header-nav-wrapper" >
        <li v-for="(item, index) in navList" :key="index" :class="index == navIndex ? 'active' : ''"
          @click="navClick(index, item.name)" >
          <router-link :to="item.path">
            {{ item.name }}
            <span v-if="item.children.length > 0" class="glyphicon glyphicon-menu-down"></span>
            <i class="underline"></i>
          </router-link>
          <dl v-if="item.children.length > 0">
            <dt v-for="(i, n) in item.children" :key="n">
              <router-link :to="i.path">{{ i.name }}</router-link>
            </dt>
          </dl>
        </li>
      </ul>
    </div>

    <!-- 手机导航 -->
    <div class="header-nav-m container-fuild visible-xs">

      <!-- 导航栏 -->
      <div class="header-nav-m-menu text-center">
        {{ menuName }}
        <div class="header-nav-m-menu-wrapper" data-toggle="collapse" data-target="#menu" @click="menuClick">
          <span :class="menuClass"></span>
        </div>
        <!-- 导航内容 -->
        <ul id="menu" class="header-nav-m-wrapper collapse">
          <li v-for="(item, index) in navList" :key="index" :class="index == navIndex ? 'active' : ''"
            @click="navClick(index, item.name)" data-toggle="collapse" data-target="#menu">
            <router-link :to="item.path">
              {{ item.name }}
              <i class="underline"></i>
            </router-link>
          </li>
        </ul>
      </div>
    </div>


  </div>
</template>

<style scoped>
/* 顶部 */
#header {
  position: fixed;
  top: 0;
  width: 100%;
  background: var(--header-background,transparent);
  transition: all ease 0.6s;
  z-index: 999999;
}

[data-vue-props="isScrolled"] #header {
  --header-background: transparent; /* 任何想要的颜色 */
}

#header .header-top {
  color: #0ee5f4;
  line-height: 40px;
  background: #1a1a1a;
}


.header-top .container {
  display: flex;
  align-items: center; /* 垂直居中 */
  font-size: 18px;
}


/* 顶部的图标 */
#header .header-top .name {
  margin: 2px;
}

@font-face {
  font-family: 'XiangJiaoDaJiangJunLingGanTi'; /* 给字体起一个名字 */
  src: url('src/assets/fonts/XiangJiaoDaJiangJunLingGanTi-2.ttf') format('truetype'); /* 指定字体文件的URL和格式 */
}

.header-top .container .SystemName-container {
  margin-top:10px;
  flex-grow: 1; /* 占据剩余空间 */
  text-align: center; /* 文本居中 */
}

#header .header-top .SystemName {
  transform: translateX(-50%);
  font-family:'XiangJiaoDaJiangJunLingGanTi', sans-serif;
}



/* 导航栏 */
#header .header-nav {
  height: 50px;
  background: transparent;
  width: 100%;
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
  background: linear-gradient(to bottom,#1a1a1a 0%, #1a1a1a 20%, rgba(0, 0, 0, 0.7) 50%, rgba(0, 0, 0, 0.3) 80%, rgba(0, 0, 0, 0.1) 100%);
}

/* 导航栏 导航容器 */
#header .header-nav-fixed .header-nav-wrapper {
  line-height: 50px;
}

#header .header-nav .header-nav-wrapper {
  line-height: 50px;
  float: right;
  margin: 0;
}

/* 导航栏 每个导航 */
#header .header-nav .header-nav-wrapper>li {
  float: left;
  margin-left: 25px;
  margin-right: 25px;
  position: relative;
  font-style: italic
}

/* 导航栏 每个导航下面的 a 链接 */
#header .header-nav .header-nav-wrapper>li>a {
  font-size: 15px;
  font-weight: bold;
  position: relative;
  color: #0ee5f4;
  padding: 5px 15px;
  z-index: 1; /* 确保文本在边框之上 */
  overflow: visible; /* 避免内容被裁剪 */
}

#header .header-nav .header-nav-wrapper>li>a::before {
  content: '';
  position: absolute;
  top: -3px; /* 边框厚度的一半 */
  left: -3px;
  right: -3px;
  bottom: -3px;
  border: 3px solid #0ee5f4;
  border-radius: 5px;
  z-index: -1; /* 确保边框在文本之下 */
  transform: skewX(-20deg); /* 应用倾斜 */
  transform-origin: 0 0; /* 从左上角开始倾斜 */
  background:black ;
}
/* 导航栏 每个导航下面的 a 链接的下划线 */
#header .header-nav .header-nav-wrapper>li>a>i {
  display: block;
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 2px;
  opacity: 0;
  transition: all 0.6s ease;
  //background-color: #1e73be;
}

/* 导航栏 每个导航下面的 a 链接的右侧小三角 */
#header .header-nav .header-nav-wrapper>li>a>span {
  font-size: 12px;
  transition: transform ease 0.5s;
}

/* 导航栏 每个导航下面的 a 链接 鼠标滑上去的样式 */
#header .header-nav .header-nav-wrapper>li>a:hover {
  color: #ffffff;
  text-decoration: none;
}

/* 导航栏 每个导航下面的 a 链接 鼠标滑上去下划线的样式 */
#header .header-nav .header-nav-wrapper>li>a:hover .underline {
  opacity: 1;
  width: 100%;
  left: 0;
}

/* 导航栏 每个导航下面的 a 链接 鼠标滑上去三角标的样式 */
#header .header-nav .header-nav-wrapper>li>a:hover span {
  transform: rotate(180deg);
}

/* 导航栏 每个导航下面的 a 链接 鼠标点击后的样式 */
#header .header-nav .header-nav-wrapper>li.active>a {
  color: #1e73be;
  text-decoration: none;
  //border-bottom: 2px solid #1e73be;
}

/* 导航栏 每个导航下面的二级导航容器 */
#header .header-nav .header-nav-wrapper>li>dl {
  display: none;
  position: absolute;
  width: 168px;
  top: 80%;
  left: 0;
  z-index: 999999;
  box-shadow: 0 0 3px 1px #ccc;
  background: #fff;
}

/* 导航栏 每个导航下面的二级导航容器的每个导航 */
#header .header-nav .header-nav-wrapper>li>dl>dt {
  width: 100%;
  padding: 10px;
  border-bottom: 1px solid #ccc;
}

/* 导航栏 每个导航下面的二级导航容器的每个导航 当鼠标滑上时的样式*/
#header .header-nav .header-nav-wrapper>li>dl>dt>a:hover {
  text-decoration: none;
}

/* 导航栏 滑上一级导航显示二级导航 */
#header .header-nav .header-nav-wrapper>li:hover dl {
  display: block;
}

#header .header-nav .header-nav-wrapper>li>dl>dt:hover {
  cursor: pointer;
  background: #ccc;
}

@media screen and (max-width: 997px) {
  #header .header-nav-m {
    position: relative;
  }

  /* 导航栏logo容器 */
  #header .header-nav-m .header-nav-m-logo {
    height: 80px;
    position: relative;
  }

  /* 导航栏logo图片 */
  #header .header-nav-m .header-nav-m-logo img {
    width: 95px;
    height: 45px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
  }

  /* 导航栏  菜单容器 */
  #header .header-nav-m .header-nav-m-menu {
    color: #fff;
    height: 50px;
    font-size: 20px;
    line-height: 50px;
    background: #474747;
    position: relative;

  }

  /* 导航栏 菜单图标 */
  #header .header-nav-m .header-nav-m-menu-wrapper {
    position: absolute;
    top: 50%;
    right: 20px;
    margin-top: -20px;
    width: 50px;
    height: 40px;
    color: #fff;
    z-index: 999999;
    font-size: 12px;
  }

  /* 导航栏 */
  #header .header-nav-m .header-nav-m-wrapper {
    position: absolute;
    top: 50px;
    left: 0;
    width: 100%;
    background: #474747;
    z-index: 9999999;
  }

  /* 导航栏 每个导航 */
  #header .header-nav-m .header-nav-m-wrapper>li {
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #ccc;
  }

  /* 导航栏 每个导航下面的 a 链接 */
  #header .header-nav-m .header-nav-m-wrapper>li>a {
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    padding: 15px 0;
    position: relative;
  }

  /* 导航栏 每个导航下面的 a 链接的右侧小三角 */
  #header .header-nav .header-nav-wrapper>li>a>span {
    font-size: 10px;
  }
}
</style>
